<template>
  <section class="jumbotron">
    <h3 class="jumbotron-heading">Search Github Users</h3>
    <div>
      <input
        type="text"
        placeholder="enter the name you search"
        v-model="searchKey"
      />&nbsp;<button @click="queryUserListHandle">Search</button>
    </div>
  </section>
</template>

<script>
import axios from "axios";

export default {
  name: "Header",
  data() {
    return {
      searchKey: "",
    };
  },
  methods: {
    async queryUserListHandle() {
      // $emit 触发事件
      this.$bus.$emit("setState", { isInit: false, isSearch: true });
      const {
        data: { items },
      } = await axios.get(
        `https://api.github.com/search/users?q=${this.searchKey}`
      );
      this.$bus.$emit("setState", { isSearch: false, userList: items });
    },
  },
};
</script>

<style>
</style>